package com.waterworld.watch.location.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.waterworld.watch.R;
import com.waterworld.watch.common.bean.TrackBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by nhuan
 * Time:2019/3/13.
 */

public class TrackAdapter extends RecyclerView.Adapter<TrackAdapter.MyHolder>{

    private Context mContext;
    private List<TrackBean> mData;


    public TrackAdapter(Context context,List<TrackBean> data) {
        mContext = context;
        mData = data;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View itemView = LayoutInflater.from(mContext).inflate(R.layout.item_track,viewGroup,false);
        itemView.getLayoutParams().height = viewGroup.getHeight()/2;
        return new TrackAdapter.MyHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder myHolder, int i) {
        myHolder.tv_time.setText(mData.get(i).getUploadTime().split(" ")[1]);
        myHolder.tv_address.setText(mData.get(i).getAddress());

    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 :mData.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_time)
        TextView tv_time;

        @BindView(R.id.tv_address)
        TextView tv_address;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
